package com.mini.cn.goods.requestinfo;

import com.alibaba.fastjson.JSONObject;
import com.mini.cn.goods.common.frame.BaseHttpNetWork;
import com.mini.cn.goods.common.frame.RequestInfo;

public class WeixinTempBackCardRequest extends BaseHttpNetWork {

    public WeixinTempBackCardRequest(RequestInfo info) {
        super(info);
        method = "POST";
    }

    @Override
    public void setHeader() {

    }

    @Override
    public byte[] setBody(RequestInfo info) {
        WeixinTempBackCardRequestInfo weixinTempBackCardRequestInfo = (WeixinTempBackCardRequestInfo) info;
        try {
            JSONObject object = new JSONObject();
            object.put("touser", weixinTempBackCardRequestInfo.openid);
            object.put("template_id", weixinTempBackCardRequestInfo.tempid);
            object.put("url", "");
            JSONObject array = new JSONObject();
            //frist
            JSONObject fristremark = new JSONObject();
            fristremark.put("value", weixinTempBackCardRequestInfo.first);
            //"color":"#173177"
            fristremark.put("color", "#173177");
            array.put("first", fristremark);
            //storeName
            JSONObject priceObject = new JSONObject();
            priceObject.put("value", weixinTempBackCardRequestInfo.name);
            array.put("storeName", priceObject);
            //orderId order
            JSONObject orderObject = new JSONObject();
            orderObject.put("value", weixinTempBackCardRequestInfo.cardid);
            array.put("orderId", orderObject);
            //orderType
            JSONObject typeObject = new JSONObject();
            typeObject.put("value", weixinTempBackCardRequestInfo.type);
            array.put("orderType", typeObject);
            //remark
            JSONObject remarkObject = new JSONObject();
            if (weixinTempBackCardRequestInfo.remark == null) {
                weixinTempBackCardRequestInfo.remark = "";
            }
            remarkObject.put("value", weixinTempBackCardRequestInfo.type);
            array.put("remark", remarkObject);
            object.put("data", array);
            String requeString = object.toString();
            System.out.println("发送模版包体 ==" + requeString);
            return requeString.getBytes("utf-8");
        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
            return null;
        }
    }

    @Override
    public void modifyUrl(RequestInfo info) {

    }
}
